import Vue from 'vue'
import VueRouter from 'vue-router'
import {IndexRouter} from './one/one'
import {SingleRouter} from './single'
import { ShopRouter } from './shop/shop'
import { LoginRouter } from './Login'

Vue.use(VueRouter)

const routes = [
  IndexRouter,
  ShopRouter,
  LoginRouter,
  ...SingleRouter,
  
  { path: "*", redirect: "/" }
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})
router.beforeEach((to,from,next)=>{
  const isLogin=!!localStorage.token
  if(to.path==='/login'){
    next()
  }else{
    isLogin?next():next('/login')
  }
})

export default router
